package cn.huhst.cas.weisiqian.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import cn.huhst.cas.weisiqian.service.NewsService;
import cn.huhst.cas.weisiqian.util.JSON;

@WebServlet("/DeleteNews.do")
public class DeleteNews extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(DeleteNews.class);
	private NewsService newsservice = null;

	public DeleteNews() {
		super();
		newsservice = new NewsService();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String newsid = request.getParameter("newsid");
		logger.info("newsid=" + newsid);
		JSON json = new JSON();

		if (newsid != null && !"".equals(newsid)) {
			boolean result = newsservice.deleteNews(newsid);
			if (result) {
				logger.info("删除新闻：" + newsid + " 成功");
				json.putOKMSG("删除新闻成功");
			} else {
				logger.error("删除新闻：" + newsid + " 失败");
				json.putErrorMSG("删除新闻失败");
			}
		} else {
			logger.error("要删除的新闻ID为空");
			json.putErrorMSG("新闻ID有误");
		}

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(json);
	}

}
